﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="GetDeviceInfo.aspx.cs" Inherits="GetDeviceInfo" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
    <title>GetDeviceInfo</title>
    <script src="js/jquery-3.3.1.js"></script>
    <script src="js/jquery-3.3.1.min.js"></script>
</head>
<body>
</body>
    <script type="text/javascript">
        var token = "";
        //获取到token的值保存到数据库(进入页面就执行)
        $(document).ready(function() { 
            $.ajax({
                type: "GET",
                async: false,
                data: {},
                url: "https://receive.symacnc.cn/v20/Verification/authorize?grant_type=clientc_credential&appid=11E96964685A7AAAB96598039B073FBC&secret=EV72BU9X2ZPV35XBR60HCWXBOUFRKTGMDJJAB3QZ&comid=11E8D1D6-636B-84CE-8CF1-00163E008027",
                dataType: "json",
                success: function (ret) {
                    token = ret.access_token
                    $.ajax({
                        type: "GET",
                        async: false,
                        data: {token:token,method:'savetoken' },
                        url: "GetDeviceInfo.ashx",
                        dataType: "json",
                        success: function (ret) {

                        },
                        error: function (t) {
                            alert(t.data);
                        }
                    })
                }
            })
            
        });

        //获取（19台）当前设备信息数据保存到数据库
        $(document).ready(function() { 
            var t;
            var tokens;
            var sysid;
            var urls = "https://receive.symacnc.cn/v20/Dept/getDeptDeviceInfo?grant_type=";
             $.ajax({
                type: "GET",
                async: false,
                data:{method:'querytoken'},
                url: "GetDeviceInfo.ashx",
                dataType: "json",
                success: function (ret) {
                    tokens = ret.token;
                    sysid = ret.sysids;
                    for (var i = 0; i < sysid.length; i++) {
                        sid = sysid[i].sysid;
                        $.ajax({
                            type: "GET",
                            async: false,
                            data: { "sysid": sid },
                            url: "" + urls + tokens + "",
                            dataType: "json",
                            success: function (ret) {
                                var a_data = {};
                                a_data["msg"] = ret.msg;
                                a_data["code"] = ret.code;
                                a_data["date"] = ret.date;
                                a_data["systemtime"] = ret.systemtime;
                                a_data["setinterval"] = ret.setinterval;
                                a_data["gjstlastminutes"] = ret.gjstlastminutes;
                                a_data["endtime"] = ret.endtime;
                                var data = ret.data;
                                a_data["sysid"] = data.sysid;
                                a_data["name"] = data.name;
                                a_data["duration_name"] = data.duration_name;
                                a_data["duration"] = data.duration;
                                a_data["warning_name"] = data.warning_name;
                                a_data["warning"] = data.warning;
                                a_data["companyid"] = data.companyid;
                                a_data["companyname"] = data.companyname;
                                a_data["deptid"] = data.deptid;
                                a_data["deptname"] = data.deptname;
                                a_data["device_type"] = data.device_type;
                                a_data["cmodel"] = data.cmodel;
                                a_data["cname"] = data.cname;
                                a_data["dmodel"] = data.dmodel;
                                a_data["dname"] = data.dname;
                                a_data["quitesysid"] = data.quitesysid;
                                a_data["worknumcol"] = data.worknumcol;
                                a_data["repstatu"] = data.repstatu;
                                a_data["repstatuname"] = data.repstatuname;
                                a_data["workstatucol"] = data.workstatucol;
                                a_data["workalarmcol"] = data.workalarmcol;
                                a_data["params_list"] = data.params_list;
                                t = a_data;
                                //将数组解析为json格式传入后台
                                deviceinfo = JSON.stringify(t);
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    data: { deviceinfo: deviceinfo, method:'savedeviceinfo'},
                                    url: "GetDeviceInfo.ashx",
                                    dataType: "json",
                                    success: function (ret) {
                                        if (i == 18) {
                                            
                                        }
                                    }
                                })
                            }
                        })
                    }
                 }
               
            })
        });
        //获取到历史设备信息（19台）
        $(document).ready(function() { 
            var t;
            var tokens;
            var sysid;
            var urls = "";
             $.ajax({
                type: "GET",
                async: false,
                data:{method:'querytoken'},
                url: "GetDeviceInfo.ashx",
                dataType: "json",
                success: function (ret) {
                    tokens = ret.token;
                    sysid = ret.sysids;
                    for (var i = 0; i < sysid.length; i++) {
                        sid = sysid[i].sysid;
                        $.ajax({
                            type: "GET",
                            async: false,
                            data: { "sysid": sid },
                            url: "https://receive.symacnc.cn/v20/Deptdevice/getDeviceCountData_HOUR?grant_type=clientc_credential&access_token="+tokens+"",
                            dataType: "json",
                            success: function (ret) {
                                var a_data = {};
                                a_data["sysid"] = sid;
                                a_data["msg"] = ret.msg;
                                a_data["code"] = ret.code;
                                var data = ret.data;
                                a_data["stime"] = data.stime;
                                a_data["etime"] = data.etime;
                                a_data["s1"] = data.s1;
                                a_data["f1"] = data.f1;
                                a_data["l1"] = data.l1;
                                a_data["t1"] = data.t1;
                                a_data["sn"] = data.sn;
                                a_data["op"] = data.op;
                                a_data["rs"] = data.rs;
                                a_data["pn"] = data.pn;
                                a_data["mpn"] = data.mpn;
                                a_data["o"] = data.o;
                                a_data["at"] = data.at;
                                a_data["alm"] = data.alm;
                                a_data["sr"] = data.sr;
                                a_data["fr"] = data.fr;
                                var statu = ret.statu;
                                a_data["alarmstatu"] = statu.alarmstatu;
                                a_data["runstatu"] = statu.runstatu;
                                t = a_data;
                                //将数组解析为json格式传入后台
                                deviceinfo = JSON.stringify(t);
                                $.ajax({
                                    type: "GET",
                                    async: false,
                                    data: { deviceinfo: deviceinfo, method:'savehistorydeviceinfo'},
                                    url: "GetDeviceInfo.ashx",
                                    dataType: "json",
                                    success: function (ret) {
                                        if (i == 18) {
                                            
                                        }
                                    }
                                })
                            }
                        })
                    }
                 }
               
            })
        });
        //获取在线设备信息
        $(document).ready(function() { 
            var t;
            var tokens;
            var urls = "https://receive.symacnc.cn/v20/Report/getStatuCount?grant_type=clientc_credential&access_token=";
             $.ajax({
                type: "GET",
                async: false,
                data:{method:'querytoken'},
                url: "GetDeviceInfo.ashx",
                dataType: "json",
                success: function (ret) {
                    tokens = ret.token;
                        $.ajax({
                            type: "GET",
                            async: false,
                            data: {},
                            url: "" + urls + tokens + "",
                            dataType: "json",
                            success: function (ret) {
                                var a_data = {};
                                var data = ret.data;
                                for (var i in data) {
                                    var a = data[i];
                                    a_data["name"] = a.name;
                                    a_data["value"] = a.value;
                                    t = a_data;
                                    //将数组解析为json格式传入后台
                                    var devicestate = JSON.stringify(t);
                                    $.ajax({
                                            type: "GET",
                                            async: false,
                                            data: { devicestate: devicestate, method:'savestate'},
                                            url: "GetDeviceInfo.ashx",
                                            dataType: "json",
                                            success: function (ret) {
                                        
                                            }
                                        })
                                }
                            }
                        })
                    }
               
            })
        });
    </script>
</html>
